package ar.com.commsys.ya.estoy;
import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;


public class MisMarcadoresOverlay extends ItemizedOverlay<OverlayItem> {
	private Context mContext;
	private ArrayList<OverlayItem> items;
	
	public MisMarcadoresOverlay(Drawable defaultMarker, Context context) { 
		super(boundCenterBottom(defaultMarker));
		items = new ArrayList<OverlayItem>();
		mContext = context;
		populate();
	}
	
	public void addNewItem(GeoPoint location, String markerText, String snippet) {
		OverlayItem marker = new OverlayItem(location, markerText, snippet);
		items.add(marker);
		populate(); 
	}
	
	public void removeItem(int index) { 
		items.remove(index);
		populate();
	}
	
	@Override
	protected OverlayItem createItem(int index) {
		return items.get(index); 
	}
	
	@Override
	public int size() {
		return items.size();
	}
	
	@Override
	protected boolean onTap(int index) {
	  OverlayItem item = items.get(index);
	  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
	  dialog.setTitle(item.getTitle());
	  dialog.setMessage(item.getSnippet());
	  dialog.show();
	  return true;
	}

}
